package core;

import branch.Branch;
import gitobject.*;
import stage.*;
import java.util.Date;

public class JitCommit {
    /**
     * command jit commit
     */
    public static void commit(String message) throws Exception {
        Index index = new Index();
        Tree tree = new Tree(index);
        String author = System.getProperty("user.name");
        String committer = System.getProperty("user.name");
        String date = new Date().toString();
        Commit commit = new Commit(tree, author, committer, message, date);
        Branch branch = new Branch(commit);
        branch.writeBranch();
        Branch.updateHEAD(branch.getName());
        System.out.println("[" + branch.getName() + " " + commit.getKey() + "]");
        System.out.println(commit.getValue());
    }
}
